package com.town.garden.entiy;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Description 通用返回结果集封装
 * @E-mail cwm3412638@163.com
 * @Author cwm
 * @Date 2022/2/28
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {


    /**
     * 返回状态码
     */
    private int code;
    /**
     * 返回消息
     */
    private String message;
    /**
     * 返回数据
     */
    private T data;

    public static Result ok() {
        return new Result(200,"ok",null);
    }

    public static Result ok(int code, String mssage, Object data) {
        return new Result(code,mssage,data);
    }

    public static Result ok(String mssage, Object data) {
        return new Result(200,mssage,data);
    }

    public static Result ok(Object data) {
        return new Result(200,"ok",data);
    }

    public static Result fail() {
        return new Result(500,"请求发生错误",null);
    }

    public static Result fail(int code, String message, Object data) {
        return new Result(code,message,data);
    }

    public static Result fail(String message, Object data) {
        return new Result(500,message,data);
    }

    public static Result fail(Object data) {
        return new Result(500,"请求发生错误",data);
    }
}
